import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.rsbot.script.methods.Interfaces;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSInterface;

class InterfaceExplorer$InterfaceTreeModel
  implements TreeModel
{
  private final Object root = new Object();
  private final ArrayList<TreeModelListener> treeModelListeners = new ArrayList();

  private final ArrayList<InterfaceExplorer.RSInterfaceWrap> interfaceWraps = new ArrayList();

  private InterfaceExplorer$InterfaceTreeModel(InterfaceExplorer paramInterfaceExplorer) {  }

  public void addTreeModelListener(TreeModelListener paramTreeModelListener) { this.treeModelListeners.add(paramTreeModelListener); }

  private void fireTreeStructureChanged(Object paramObject)
  {
    this.treeModelListeners.size();
    TreeModelEvent localTreeModelEvent = new TreeModelEvent(this, new Object[] { paramObject });

    for (TreeModelListener localTreeModelListener : this.treeModelListeners)
      localTreeModelListener.treeStructureChanged(localTreeModelEvent);
  }

  public Object getChild(Object paramObject, int paramInt)
  {
    if (paramObject == this.root)
      return this.interfaceWraps.get(paramInt);
    if ((paramObject instanceof InterfaceExplorer.RSInterfaceWrap)) {
      return new InterfaceExplorer.RSComponentWrap(this.this$0, ((InterfaceExplorer.RSInterfaceWrap)paramObject).wrapped.getComponents()[paramInt]);
    }
    if ((paramObject instanceof InterfaceExplorer.RSComponentWrap)) {
      return new InterfaceExplorer.RSComponentWrap(this.this$0, ((InterfaceExplorer.RSComponentWrap)paramObject).wrapped.getComponents()[paramInt]);
    }

    return null;
  }

  public int getChildCount(Object paramObject) {
    if (paramObject == this.root)
      return this.interfaceWraps.size();
    if ((paramObject instanceof InterfaceExplorer.RSInterfaceWrap))
      return ((InterfaceExplorer.RSInterfaceWrap)paramObject).wrapped.getComponents().length;
    if ((paramObject instanceof InterfaceExplorer.RSComponentWrap)) {
      return ((InterfaceExplorer.RSComponentWrap)paramObject).wrapped.getComponents().length;
    }
    return 0;
  }

  public int getIndexOfChild(Object paramObject1, Object paramObject2) {
    if (paramObject1 == this.root)
      return this.interfaceWraps.indexOf(paramObject2);
    if ((paramObject1 instanceof InterfaceExplorer.RSInterfaceWrap)) {
      return Arrays.asList(((InterfaceExplorer.RSInterfaceWrap)paramObject1).wrapped.getComponents()).indexOf(((InterfaceExplorer.RSComponentWrap)paramObject2).wrapped);
    }

    if ((paramObject1 instanceof InterfaceExplorer.RSComponentWrap)) {
      return Arrays.asList(((InterfaceExplorer.RSComponentWrap)paramObject1).wrapped.getComponents()).indexOf(((InterfaceExplorer.RSComponentWrap)paramObject2).wrapped);
    }

    return -1;
  }

  public Object getRoot() {
    return this.root;
  }

  public boolean isLeaf(Object paramObject) {
    return ((paramObject instanceof InterfaceExplorer.RSComponentWrap)) && (((InterfaceExplorer.RSComponentWrap)paramObject).wrapped.getComponents().length == 0);
  }

  public void removeTreeModelListener(TreeModelListener paramTreeModelListener) {
    this.treeModelListeners.remove(paramTreeModelListener);
  }

  public boolean searchMatches(RSComponent paramRSComponent, String paramString)
  {
    return paramRSComponent.getText().toLowerCase().contains(paramString.toLowerCase());
  }

  public void update(String paramString)
  {
    this.interfaceWraps.clear();

    label174: for (RSInterface localRSInterface : InterfaceExplorer.access$000(this.this$0).getAll())
    {
      for (RSComponent localRSComponent1 : localRSInterface.getComponents())
      {
        if (searchMatches(localRSComponent1, paramString)) {
          this.interfaceWraps.add(new InterfaceExplorer.RSInterfaceWrap(this.this$0, localRSInterface));
          break;
        }

        for (RSComponent localRSComponent2 : localRSComponent1.getComponents()) {
          if (searchMatches(localRSComponent2, paramString)) {
            this.interfaceWraps.add(new InterfaceExplorer.RSInterfaceWrap(this.this$0, localRSInterface));
            break label174;
          }
        }
      }
    }
    fireTreeStructureChanged(this.root);
  }

  public void valueForPathChanged(TreePath paramTreePath, Object paramObject)
  {
  }
}